# -*- coding: utf-8 -*-
from ....CLAPI import CLModuleProxy

from ._Define import \
    BaseSelectCanvas as _BaseSelectCanvas, \
    CustomMainSetCanvas as _CustomMainSetCanvas, \
    PageRegistry as _PageRegistry

lambda: "By Zero123"

_proxy = CLModuleProxy.fromTargetMod("Features.GameSet.UI")

@_proxy.bindTarget
class BaseSelectCanvas(_BaseSelectCanvas):
    pass

@_proxy.bindTarget
class CustomMainSetCanvas(_CustomMainSetCanvas):
    pass

class PageRegistry(_PageRegistry):
    """ 注册相关功能推荐在MOD加载完毕事件下进行 """
    @staticmethod
    def registerPage(page):
        # type: (BaseSelectCanvas) -> bool
        """ 注册自定义页面 """
        mainGameSet = _proxy.findObj("MainGameSet")
        if not mainGameSet:
            return False
        CUSTOM_CANVAS_LIST = getattr(mainGameSet, "CUSTOM_CANVAS_LIST", None)
        if CUSTOM_CANVAS_LIST is None:
            return False
        elif isinstance(CUSTOM_CANVAS_LIST, list):
            CUSTOM_CANVAS_LIST.append(page)
            return True
        elif isinstance(CUSTOM_CANVAS_LIST, set):
            CUSTOM_CANVAS_LIST.add(page)
            return True
        return False

    _CORE = CLModuleProxy.fromTargetMod("Features.GameSet.BaseSet.Core")

    @staticmethod
    def addBasicSetting(render):
        # type: (BaseSelectCanvas.BaseRender) -> bool
        """ 追加注册基础设置页面的渲染内容(必须在OnLocalPlayerStopLoading之前完成后续会被冻结注册表) """
        if not PageRegistry._CORE:
            return False
        Static = PageRegistry._CORE.findObj("Static")
        STD_CUSTOM_MAIN_SET_LIST = getattr(Static, "STD_CUSTOM_MAIN_SET_LIST", [])
        if isinstance(STD_CUSTOM_MAIN_SET_LIST, list):
            STD_CUSTOM_MAIN_SET_LIST.append(render)
            return True
        elif isinstance(STD_CUSTOM_MAIN_SET_LIST, set):
            STD_CUSTOM_MAIN_SET_LIST.add(render)
            return True
        return False